package cn.golxen.rsms.redis;

import cn.golxen.rsms.bean.bo.PlaceOrderBo;
import cn.golxen.rsms.mapper.LogMapper;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

@Service
@Slf4j
public class PayRedis {

    @Autowired
    RedisTemplate<String, String> redisTemplate;
    @Autowired
    LogMapper logMapper;

    @Cacheable(value = "place_orderBo", key = "#orderId",unless = "#placeOrderBo == null")
    public PlaceOrderBo placeOrderByNative(PlaceOrderBo placeOrderBo, String orderId) {
        return placeOrderBo;
    }

    @CacheEvict(value = "place_orderBo", key = "#orderId")
    public int queryOrder(String orderId) {
//        if (isDone == 1)
//            return logMapper.updateOrderIsDone(orderId, customerId, isDone);
//        else return 0;
        return 1;
    }

    public Set<String> getPayingOrderList(int storeId) {
        Set<String> payingOrderList = redisTemplate.keys("place_orderBo::" + storeId + "*");
        return payingOrderList;
    }

}

